package com.muqi.app.qlearn.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.muqi.app.qlearn.modles.CreditInfo;
import com.muqi.app.qlearn.student.R;

import com.muqi.app.utils.ChineseUtils;

public class MyIntegeralAdapter extends BaseAdapter {
	private ArrayList<CreditInfo> infos;
	private Context content;
	private LayoutInflater inflater;

	public MyIntegeralAdapter(ArrayList<CreditInfo> infos, Context content) {
		super();
		this.infos = infos;
		this.content = content;
		inflater = LayoutInflater.from(content);
	}

	@Override
	public int getCount() {
		return infos.size();
	}

	@Override
	public Object getItem(int arg0) {
		return infos.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int arg0, View arg1, ViewGroup arg2) {
		TreeViewHolder holder = null;
		CreditInfo itemInfo = infos.get(arg0);
		if (arg1 == null) {
			arg1 = inflater.inflate(R.layout.item_my_integeral, null);
			holder = new TreeViewHolder();

			holder.itemTime = (TextView) arg1
					.findViewById(R.id.item_integeral_time);
			holder.itemName = (TextView) arg1
					.findViewById(R.id.item_integeral_name);

			holder.itemScore = (TextView) arg1
					.findViewById(R.id.item_integeral_score);

			arg1.setTag(holder);
		} else {
			holder = (TreeViewHolder) arg1.getTag();
		}
		if (itemInfo != null) {
			holder.itemName.setText(itemInfo.description);
			if(itemInfo.quantity.contains("-")){
				holder.itemScore.setText(itemInfo.quantity);
			}else{
				holder.itemScore.setText("+"+itemInfo.quantity);
			}
			holder.itemTime.setText(itemInfo.create_time);
		}

		return arg1;
	}

	private class TreeViewHolder {

		TextView itemName;
		TextView itemTime;
		TextView itemScore;

	}

}
